package com.lagou.homework;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class WorkTest {
        public static void main(String[] args) {
            //1.创建List集合指向ArrayList的对象，
            // 在List集合中新增三个员工信息 并打印List中员工信息
            List list = new ArrayList();
            list.add(new Worker("凤姐",18,20000));
            list.add(new Worker("欧阳峰",60,8000));
            list.add(new Worker("刘德华",40,30000));
            System.out.println(list);
            //2.在"欧阳峰"之前新增一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
            System.out.println("---------------------------------------");
            list.add(1, new Worker("张柏芝",35,3300));
            System.out.println(list);
            System.out.println("---------------------------------------");
            //3.删除"刘德华"这个员工的信息
            list.remove(new Worker("刘德华",40,30000));
            System.out.println(list);
            System.out.println("---------------------------------------");
            //4.利用for 循环遍历，打印List集合中所有员工的信息
            for(int i = 0;i<list.size();i++) {
                Worker wk = (Worker) list.get(i);
                System.out.println(wk);
            }
            System.out.println("---------------------------------------");
            //5.利用迭代遍历，对List 中所有的员工调用work方法
            Iterator<Worker> it = list.iterator();
            //判断是否为最后一个元素，不是调用work方法 是循环结束
            while(it.hasNext()) {
                Worker wk = it.next();
                wk.work();
            }
        }
    }

